package ferror

import (
	"gitee.com/lailonghui/vehicle-supervision-framework/pkg/resultcode"
	"github.com/pkg/errors"
)

// Wrap error, include current caller
func Wrap(msg string, subError error) error {
	if subError == nil {
		return nil
	}
	return errors.Wrap(subError, msg)
}

func WrapWithCode(msg string, code string, subError error) error {
	if subError == nil {
		return NewWithCode(msg, code)
	}
	return Wrap(code+":"+msg, subError)
}

// New error, include current caller
func New(msg string) error {
	return NewWithCode(msg, resultcode.FAIL)
}

func NewWithCode(msg, code string) error {
	return AppError{
		Msg:      msg,
		Code:     code,
		SubError: errors.New(code + ":" + msg),
	}
}
